package com.cskaoyan.mall.promo.task;


import com.cskaoyan.mall.promo.service.PromoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
@Slf4j
@EnableScheduling
public class PromoTask {
    @Autowired
    PromoService promoService;
    @Scheduled(cron = "0 0 2 * * ?")//正常是每天凌晨点更新
//    @Scheduled(cron = "0/10 * * * * ?")//写个假的
//    @PostConstruct
    public void importIntoRedisTsk(){
        log.info("备份开始");
        //这个地方应该调用对应的service即可
        promoService.importIntoRedis();
        log.info("备份结束");
    }

    //这个地方再写个每天定时清楚库存的接口
    @Scheduled(cron = "0 0 22 * * ?")
    public void finishPromo(){
        log.info("促销结束，开始清除数据");
        promoService.clearRedisCache();
        log.info("促销结束，完成清除数据");
    }
}
